#include <Inventor/Win/SoWin.h>
#include <Inventor/Win/viewers/SoWinExaminerViewer.h>
#include <Inventor/nodes/SoCube.h>
#include <Inventor/nodes/SoCylinder.h>
#include <Inventor/nodes/SoSphere.h>
#include <Inventor/nodes/SoTransform.h>
#include <Inventor/nodes/SoDirectionalLight.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <Inventor/nodes/SoSeparator.h>

#include <tchar.h>


int _tmain(int argc, _TCHAR* argv[])
{
   HWND myWindow = SoWin::init(argv[0]);
   if (myWindow == nullptr) exit(1);

  // Robot with legs

  // Construct parts for legs (thigh, calf and foot)
  SoCube *thigh = new SoCube;     
  thigh->width = 1.2F;
  thigh->height = 2.2F;
  thigh->depth = 1.1F;

  SoTransform *calfTransform = new SoTransform;
  calfTransform->translation.setValue(0, -2.25, 0.0);

  SoCube *calf = new SoCube;
  calf->width = 1;
  calf->height = 2.2F;
  calf->depth = 1;

  SoTransform *footTransform = new SoTransform;
  footTransform->translation.setValue(0, -2, .5);

  SoCube *foot = new SoCube;
  foot->width = 0.8F;
  foot->height = 0.8F;
  foot->depth = 2;

  // Put leg parts together
  SoGroup *leg = new SoGroup;      
  leg->addChild(thigh);
  leg->addChild(calfTransform);
  leg->addChild(calf);
  leg->addChild(footTransform);
  leg->addChild(foot);

  SoTransform *leftTransform = new SoTransform;
  leftTransform->translation = SbVec3f(1, -4.25, 0);

  // Left leg
  SoSeparator *leftLeg = new SoSeparator;   
  leftLeg->addChild(leftTransform);
  leftLeg->addChild(leg);

  SoTransform *rightTransform = new SoTransform;
  rightTransform->translation.setValue(-1, -4.25, 0);

  // Right leg
  SoSeparator *rightLeg = new SoSeparator;   
  rightLeg->addChild(rightTransform);
  rightLeg->addChild(leg);

  // Parts for body
  SoTransform *bodyTransform = new SoTransform;    
  bodyTransform->translation.setValue(0.0, 3.0, 0.0);

  SoMaterial *bronze = new SoMaterial;
  bronze->ambientColor.setValue(.33F, .22F, .27F);
  bronze->diffuseColor.setValue(.78F, .57F, .11F);
  bronze->specularColor.setValue(.99F, .94F, .81F);
  bronze->shininess = .28F;

  SoCylinder *bodyCylinder = new SoCylinder;
  bodyCylinder->radius = 2.5;
  bodyCylinder->height = 6;

  // Construct body out of parts 
  SoSeparator *body = new SoSeparator;  
  body->addChild(bodyTransform);      
  body->addChild(bronze);
  body->addChild(bodyCylinder);
  body->addChild(leftLeg);
  body->addChild(rightLeg);

  // Head parts
  SoTransform *headTransform = new SoTransform;   
  headTransform->translation.setValue(0, 7.5, 0);
  headTransform->scaleFactor.setValue(1.5, 1.5, 1.5);

  SoMaterial *silver = new SoMaterial;
  silver->ambientColor.setValue(.2F, .2F, .2F);
  silver->diffuseColor.setValue(.6F, .6F, .6F);
  silver->specularColor.setValue(.5F, .5F, .5F);
  silver->shininess = .5;

  SoSphere *headSphere = new SoSphere;

  // Construct head
  SoSeparator *head = new SoSeparator;      
  head->addChild(headTransform);
  head->addChild(silver);
  head->addChild(headSphere);
   
  // Robot is just head and body
  SoSeparator *robot = new SoSeparator;  
  robot->addChild(body);               
  robot->addChild(head);

   // Set up viewer:
   SoWinExaminerViewer *myViewer = new SoWinExaminerViewer(myWindow);
   myViewer->setSceneGraph(robot);
   myViewer->setTitle("Examiner Viewer");
   myViewer->show();

   SoWin::show(myWindow);
   SoWin::mainLoop();
}